﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Cookies;
using Cookies.Controllers;
using Rhino.Mocks;

namespace Cookies.Tests.Controllers
{
    [TestClass]
    public class HomeControllerTest
    {
        private MockRepository mocks;
        private HttpContextBase mockHttpContext;

        [TestInitialize]
        public void SetupHttpContext()
        {
            mocks = new MockRepository();
            //Mock setup
            mockHttpContext = mocks.DynamicMock<HttpContextBase>();
            HttpRequestBase mockHttpRequest = mocks.DynamicMock<HttpRequestBase>();
            SetupResult.For(mockHttpContext.Request).Return(mockHttpRequest);

            HttpCookieCollection cookies = new HttpCookieCollection();
            cookies.Add(new HttpCookie("LastLogin", "Yesterday"));

            Expect.Call(mockHttpRequest.Cookies).Return(cookies);

            mocks.ReplayAll();
        }

        [TestMethod]
        public void About()
        {
            // Arrange
            HomeController controller = new HomeController();
            controller.ControllerContext = new ControllerContext(
                mockHttpContext,
                new RouteData(),
                controller);

            // Act
            ActionResult actionResult = controller.About();

            // Assert
            ViewResult result = actionResult as ViewResult;
            Assert.IsNotNull(result, "Not a RenderView Result");
            ViewDataDictionary viewData = result.ViewData;
            Assert.AreEqual("Yesterday", viewData["LastLogin"]);
            mocks.VerifyAll();
        }
    }
}
